package com.sirdc.modules.sys.web.HardWork;

import com.sirdc.modules.utils.ObjectUtils;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.Project.entity.NodeNewfile;
import net.huashitong.Project.service.NodeNewFilterService;
import net.huashitong.oversee.filter.CoordinateFilter;
import net.huashitong.oversee.filter.SupervisionTaskFilter;
import net.huashitong.oversee.service.CoordinateService;
import net.huashitong.oversee.service.SupervisionTaskService;
import net.huashitong.user.entity.BnpUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.util.WebUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * 节点备案清单管理
 * Created by hyp1202 on 2018/7/12.
 */
@Controller
@RequestMapping("/nodeFilter")
public class SysNodeFilterMangerController {

    @Autowired
    private NodeNewFilterService nodeNewFilterService;
    @Autowired
    private SupervisionTaskService supervisionTaskService;
    @Autowired
    private CoordinateService coordinateService;

    @ModelAttribute("headType")
    public String returnHeadType(){
        return "管理模块";
    }

    @RequestMapping(value = "/go/list")
    public String getNodeFilter(@ModelAttribute NodeNewfile nodeNewfile, Model model, HttpServletRequest request){
//        List<NodeNewfile> fileList = new ArrayList<>();

        BnpUser bu=(BnpUser) WebUtils.getSessionAttribute(request, "user");
        if (ObjectUtils.isBlank(bu)){
            return "/modules/login/login";
        }
        model.addAttribute("leftType","各节点文件清单");

        int myTaskNum = (int) WebUtils.getSessionAttribute(request, "myTaskNum");
        int quetionNum = (int) WebUtils.getSessionAttribute(request, "quetionNum");
        model.addAttribute("myTaskNum", myTaskNum);
        model.addAttribute("quetionNum", quetionNum);

        //待办任务个数
        int nodeCount = (int) WebUtils.getSessionAttribute(request, "nodeCount");
        model.addAttribute("nodeCount", nodeCount);

        int myTackTaskNum = (int) WebUtils.getSessionAttribute(request, "myTackTaskNum");
        model.addAttribute("myTackTaskNum", myTackTaskNum);

        return "/modules/hardWork/user_qdManger";
    }
    @ResponseBody
    @RequestMapping(value = "/go/lists",method = RequestMethod.GET)
    public Map<String,List<NodeNewfile>> getNode(HttpServletRequest request,Model model){

        Map<String,List<NodeNewfile>> map = new LinkedHashMap<>();
        List<NodeNewfile> list = nodeNewFilterService.queryNodeName();
        for (NodeNewfile file:list) {
            List<NodeNewfile> fileList = nodeNewFilterService.queryNodeNewfile(file);
            map.put(fileList.get(0).getNodeId()+file.getNodeName(),fileList);
        }

        int myTaskNum = (int) WebUtils.getSessionAttribute(request, "myTaskNum");
        int quetionNum = (int) WebUtils.getSessionAttribute(request, "quetionNum");
        model.addAttribute("myTaskNum", myTaskNum);
        model.addAttribute("quetionNum", quetionNum);

        int myTackTaskNum = (int) WebUtils.getSessionAttribute(request, "myTackTaskNum");
        model.addAttribute("myTackTaskNum", myTackTaskNum);

        //待办任务个数
        int nodeCount = (int) WebUtils.getSessionAttribute(request, "nodeCount");
        model.addAttribute("nodeCount", nodeCount);

        return map;
    }
}
